import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
//elementplus按需引入
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// import Icons from "unplugin-icons/vite";
// import IconsResolver from "unplugin-icons/resolver";
// 自动按需导入 element-plus 样式
//import ElementPlus from 'unplugin-element-plus/vite'
const pathSrc = path.resolve(__dirname, "src");
// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 8080,
  },
  base: "./",
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"), //src别名配置
      "@images": path.resolve(__dirname, "src/assets/images"), //src别名配置
      "@assets": path.resolve(__dirname, "src/assets"),
      "@icon": path.resolve(__dirname, "src/assets/images/icon"),
      "@components": path.resolve(__dirname, "src/components"),
      "@views": path.resolve(__dirname, "src/views"),
      "@store": path.resolve(__dirname, "src/store"),
      "@api": path.resolve(__dirname, "src/api"),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        //additionalData: `@use "@/styles/element/index.scss" as *;`,
      },
    },
  },
  build: {
    outDir: "RHIS", //输出文件名
    assetsDir: "assets", //指定静态资源存放路径
    rollupOptions: {
      output: {
        chunkFileNames: "js/[name]-[hash].js", //js文件输出路径
        entryFileNames: "js/[name]-[hash].js",
        assetFileNames: "[ext]/[name]-[hash].[ext]",
      },
    },
  },
  plugins: [
    vue({
      refTransform: true // 开启ref转换
    }),
    AutoImport({
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      //imports: ["vue","vuex", "vue-router", "@vueuse/core"],
      resolvers: [
        // 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
        ElementPlusResolver(),
        // 自动导入图标组件
        // IconsResolver({
        //   prefix: "Icon",
        // }),
      ],
      dts: path.resolve(pathSrc, "auto-imports.d.ts"),
    }),
    Components({
      // dirs 指定组件所在位置，默认为 src/components
      // 可以让我们使用自己定义组件的时候免去 import 的麻烦
      dirs: ["src/components/"],
      // 配置需要将哪些后缀类型的文件进行自动按需引入，'vue'为默认值
      extensions: ["vue"],
      // 解析组件，这里以 Element Plus 为例
      resolvers: [
        // 自动导入 Element Plus 组件
        ElementPlusResolver({
          //importStyle: "sass",
        }),
        // 自动注册图标组件
        // IconsResolver({
        //   enabledCollections: ["ep"],
        // }),
      ],
      // 生成components.d.ts
      dts: true,
      // 遍历子目录
      deep: true,
    }),
   //  Icons({
   //    // scale: 1,
   //    // defaultClass: "inline-blok",
	  // compiler:"vue3",
   //    autoInstall: true,
   //  }),
    // ElementPlus({
    //   useSource: true,
    // }),
  ],
});
